import routerconfig from "./routerConfig";
import {BrowserRouter,Routes,Route,Navigate} from "react-router-dom"
import {Suspense} from "react"
let RouterView = ()=>{
    let renderRoute = (routerconfig)=>{
        return routerconfig.map((item,index)=>{
            return item.path ? <Route path={item.path} key={index} element={<item.element></item.element>}>
                        {
                            item.children && renderRoute(item.children)
                        }
            </Route>:<Route path={item.from} element={<Navigate to={item.to}></Navigate>} key={index}></Route>
        })
    }
    return <BrowserRouter>
             <Suspense fallback={<div>...loading</div>}>
                <Routes>
                    {
                        renderRoute(routerconfig)
                    }

                </Routes>
                </Suspense>
           </BrowserRouter>
}
export default RouterView